<?php
class Application extends Base
{
    public static $PASS = "PASS";

    public function loadMyCurrentVoteApplication($userId, $voteId)
    {
        $sql = "select * from applications where userId =$userId and voteId=$voteId";
        return $this->_db->getone($sql);
    }

    protected function getPrimaryKey()
    {
        return "applicationId";
    }

    protected function getTableName()
    {
        return "applications";
    }

    public function pass($id)
    {
        return $this->updateStatus($id, Application::$PASS);
    }

    public function findLast($count)
    {
        return $this->_db->getAll("select * from " . $this->getTableName() . " where status = '" . Application::$PASS . "' order by createDate desc limit $count");
    }

    protected function competeRecord($post)
    {
        $c = $this->getCredentials();
        return array(
            "name" => $post['name'],
            "nickname" => $post['nickname'],
            "gender" => $post['gender'],
            "hobby" => $post['hobby'],
            "introduce" => strip_tags($post['introduce']),
            "motto" => $post['motto'],
            "photo" => $post['photo'],
            "userId" => $c['userId'],
            "voteId" => $post['voteId'],
            "height" => $post['height'],
            "weight" => $post['weight'],
            "waistline" => $post['waistline'],
            "bust" => $post['bust'],
            "hip" => $post['hip'],
            "createDate" => Util::getCurrentDate(),
            "birthday" => $post['birthday']
        );
    }

    public function isApped($userId, $voteId)
    {
        $sql = "select count(1) as count from applications where userId= $userId and voteId=$voteId";
        $count = $this->_db->getone($sql);
        return $count['count'] > 0;
    }

}

?>